import { UserRepositoryAbstract } from "../user-abstract.repository";
import { User } from "../entities/user.entity";
import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { UserAdapter } from "../user.interface";

export class MongooseRepository extends UserRepositoryAbstract implements UserAdapter {
    constructor(@InjectModel('User') private readonly userModel: Model<User>,) {
        super();
    }

    findAll(page: number = 10, limit: number = 1): Promise<any[]> {
        return this.userModel.find().skip((page - 1) * limit).limit(limit).exec();
    }

    find(): Promise<any[]> {
        return this.userModel.find()
    }
    create(userObj: any): Promise<any> {
        return this.userModel.create(userObj)
    }
    update(userObj: any): Promise<any> {
        return this.userModel.updateOne(userObj)
    }

    delete(id: string): Promise<any> {
        return this.userModel.deleteOne({ _id: id })
    }

}